package com.test.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.test.entity.MemberType;
import com.test.entity.Orders;
import com.test.entity.UserInfo;

public class UserInfoDAO extends HibernateDaoSupport {
	public UserInfo queryByNP(String userId, String passWord) {
		List<UserInfo> list = this.getHibernateTemplate()
				.find("from UserInfo where userId=? and passWord=?", userId,
						passWord);
		UserInfo userInfo = null;
		if (list.size() > 0) {
			return list.get(0);
		} else {
			return userInfo;
		}
	}

	public void addUserInfo(UserInfo userInfo) {
		this.getHibernateTemplate().save(userInfo);
	}

	public List<MemberType> queryMember() {
		List<MemberType> list = this.getHibernateTemplate().find(
				"from MemberType where id=?", 1);
		return list;
	}

	public UserInfo querymoney(String name) {
		List<UserInfo> list = this.getHibernateTemplate().find(
				"from UserInfo where userName=?", name);
		UserInfo userInfo = null;
		if (list.size() > 0) {
			userInfo = list.get(0);
		}
		return userInfo;
	}

	public List<UserInfo> queryIdMoney(String userid) {
		List<UserInfo> list = this.getHibernateTemplate().find(
				"from UserInfo where userId=?", userid);
		return list;
	}

	public void updateMoney(UserInfo userInfo) {
		this.getHibernateTemplate().update(userInfo);
	}

	public void updateUserInfo(UserInfo userInfo) {
		this.getHibernateTemplate().update(userInfo);
	}

	public List<Orders> OrderCount(int id) {
		List<Orders> list = this
				.getHibernateTemplate()
				.find("select count(*) as Num from Orders where CreateTime>(GETDATE()-30) and CreateTime<GETDATE() and userid=?",
						id);
		return list;
	}

}
